package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.MesProcessDetails;
import com.woniuxy.mesboot.mapper.MesProcessDetailsMapper;
import com.woniuxy.mesboot.service.ProcessDetailsService;
import com.woniuxy.mesboot.util.Result;
import com.woniuxy.mesboot.vo.MesProcessDetailVO;
import com.woniuxy.mesboot.vo.ProcessVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("processDetails")
public class ProcessDetailsController {
    @Resource
    private ProcessDetailsService processDetailsService;

    @Resource
    private MesProcessDetailsMapper mesProcessDetailsMapper;

    @PostMapping("{id}")
    public Result queryaha(@PathVariable Integer id) {
        final List<MesProcessDetailVO> mesProcessDetailVOS = mesProcessDetailsMapper.selectByOperationProcedureId(id);
        return Result.ok().data("list",mesProcessDetailVOS);
    }

    @GetMapping("selectlist")
    public Result queryList() {
        final List<ProcessVO> selectlist = processDetailsService.selectlist();
        return Result.ok().data("list",selectlist);
    }

    @GetMapping
    public Result queryAll() {
        List<MesProcessDetails> i = processDetailsService.selectAll();
        return Result.ok().data("list", i);

    }

//    @PostMapping
//    public Result insert(@RequestBody PPDTO record) {
//        int insert = processDetailsService.insertSelective(record);
//        if (insert > 0) {
//            return Result.ok("添加成功");
//        } else {
//            return Result.error("添加失败");
//        }
//    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        int i = processDetailsService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MesProcessDetails mesProcessDetails = processDetailsService.selectByPrimaryKey(id);
        return Result.ok().data("details" ,mesProcessDetails);
    }

    @PutMapping
    public Result update(@RequestBody MesProcessDetails record) {
        int i = processDetailsService.updateByPrimaryKey(record);
        if (i > 0) {
            return Result.ok("修改成功");

        } else {
            return Result.error("修改失败");
        }
    }
}
